package com.fr.lintcode;

import org.junit.Test;

/**
*作者：furong
*日期：2017年2月8日
*时间：下午4:58:06
*/
public class Q373 {
    /**
     * @param nums: an array of integers
     * @return: nothing
     */
    public void partitionArray(int[] nums) {
        if (nums == null || nums.length <= 1) {
            return;
        }
        int left = 0;
        int right = nums.length - 1;
        while (left < right) {
            while (nums[left] % 2 == 1) {
                left++;
            }
            while (nums[right] % 2 == 0) {
                right--;
            }
            if (left < right) {
                int tmp = nums[left];
                nums[left] = nums[right];
                nums[right] = tmp;
            }
        }
    }

    @Test
    public void testA() {
        int nums[] = { 1, 2, 3, 4, 5, 6, 7 };
        partitionArray(nums);
        for (int i : nums) {
            System.out.println(i);
        }
    }
}
